<template>
    {{form}}
    <h2 style="text-align: center;">注册页面</h2>
    <table class="table">
        <tr class="form-inline">
            <td>用户名</td>
            <td>
                <input type="text" class="form-control" v-model="form.name">
            </td>
        </tr>
        <tr class="form-inline">
            <td>密码</td>
            <td>
                <input type="password" class="form-control" v-model="form.password">
            </td>
        </tr>
        <tr class="form-inline">
            <td colspan="2" style="text-align: center;">
                <button class="btn btn-success" @click="zhuce">注册</button>
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import "bootstrap/dist/css/bootstrap.min.css"
import router from '@/router';

const form =reactive({
  "name": "",
    "password": "",
  "type": "管理员",
})

const zhuce = () => {
    if (form.name == "") {
        alert("用户名不能为空");
        return;
    }
    if (form.password == "") {
        alert("密码不能为空");
        return;
    }
    axios.post("https://localhost:7013/api/user/Login",form).then(res => {
        if (res.data > 0) {
            alert("注册成功");
            router.push("/denglulist");
        }
        else {
            alert("注册失败");
            return;
        }
    })
}

</script>